package com.lfh.itos.util;

import java.util.List;

/**
 * 分页查询的数据类
 * @author zhanbing
 *
 * @param <T>
 */
public class PageInfo<T> {
	
	/**
	 * 开始位置
	 */
	private long start = 0;
	
	/**
	 * 查询的数据数量
	 */
	private long limit = 15;
	
	/**
	 * 记录集
	 */
	private List<T> result = null;
	
	/**
	 * 总记录数
	 */
	private long totalCount = -1;
	
	/**
	 * 总页数
	 */
	private long totalPage = 0;
	
	/**
	 * 当前页数
	 */
	private long currentPage = 1;

	/**
	 * 根据指定页码, 创建分页对象
	 * 
	 * @param currentPage
	 */
	public PageInfo(int currentPage) {
		this.currentPage = currentPage;
		this.start = (this.currentPage - 1) * this.limit;
	}
	
	/**
	 * 根据指定页面 + 每页显示数 创建分页对象
	 * 
	 * @param currentPage
	 * @param limit
	 */
	public PageInfo(long currentPage, long limit) {
		this.limit = limit;
		this.currentPage = currentPage;
		this.start = (this.currentPage - 1) * this.limit;
	}
	
	/**
	 * 设置查询结果集
	 * 
	 * @param totalCount
	 * @param result
	 */
	public void setResult(Long totalCount, List<T> result) {
		this.totalCount = totalCount;
		this.result = result;
		this.totalPage = this.totalCount / this.limit;
		if (this.totalCount % this.limit > 0) {
			this.totalPage += 1;
		}
	}

	public long getStart() {
		return start;
	}

	public long getLimit() {
		return limit;
	}

	public List<T> getResult() {
		return result;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public long getTotalPage() {
		return totalPage;
	}

	public long getCurrentPage() {
		return currentPage;
	}
	
}
